package com.epam.iunna.bookshop.model.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtils {
    private DBUtils(){};
    
    /**
     * Safely close db connection
     * 
     * @param connection
     *            connection to db
     * @param statement
     *            statement to db * @param result result set from db
     * @throws SQLException
     */
    public static void closeConnection(Connection connection, Statement statement,
            ResultSet result) throws SQLException {
        try {
            if (result != null) {
                result.close();// close result set
            }
        } finally {
            try {
                if (statement != null) {
                    statement.close();// close statement
                }
            } finally {
                // If we don't have a error, close the connection!
                if (connection != null) {
                    connection.close();
                }
            }
        }
    }

}
